/**
 * Created by Administrator on 2017/2/28 0028.
 */


import React, { Component } from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    Navigator,
    BackAndroid
} from 'react-native';

var Login = require('./../else/login');
var Register = require('./../else/register');
var forgetP = require('./../else/forgetP');
var confirmP = require('./../else/confirmP');

var DefaultView = React.createClass({
    render(){
        return (
            <View >
                <Text>Default view</Text>
            </View>
        )
    }
});

var NaviModule = React.createClass({

    configureScene(route){
        return Navigator.SceneConfigs.FadeAndroid;
    },

    renderScene(route, navigator){
        var Component = null;this._navigator = navigator;
        switch (route.name){
            case "login":
                Component = Login;
                break;
            case "register":
                Component = Register;
                break;
            case "forgetP":
                Component = forgetP;
                break;
            case "confirmP":
                Component = confirmP;
                break;
            default: //default view
                Component = DefaultView;
        }

        return <Component navigator={navigator} />
    },

    componentDidMount() {
        var navigator = this._navigator;
        BackAndroid.addEventListener('hardwareBackPress', function() {
            if (navigator && navigator.getCurrentRoutes().length > 1) {
                navigator.pop();
                return true;
            }
            return false;
        });
    },


    componentWillUnmount() {
        BackAndroid.removeEventListener('hardwareBackPress');
    },

    render() {
        return (
            <Navigator
                initialRoute={{name: 'login'}}
                configureScene={this.configureScene}
                renderScene={this.renderScene} />
        );
    }

});

module.exports = NaviModule;